﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms
{
    public partial class ComboBoxDemo : Form
    {
        public ComboBoxDemo()
        {
            InitializeComponent();
        }

        private void ComboBoxDemo_Load(object sender, EventArgs e)
        {
            cboCountry.SelectedIndex = 0;
        }

        private void cboCountry_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch(cboCountry.SelectedIndex)
            {
                case 0:
                    cboCity.Items.Clear();
                    cboCity.Items.Add("北京");
                    cboCity.Items.Add("上海");
                    cboCity.Items.Add("广州");
                    cboCity.SelectedIndex = 0;
                    break;
                case 1:
                    cboCity.Items.Clear();
                    cboCity.Items.Add("纽约");
                    cboCity.Items.Add("华盛顿");
                    cboCity.Items.Add("渥太华");
                    cboCity.SelectedIndex = 0;
                    break;
                case 2:
                    cboCity.Items.Clear();
                    cboCity.Items.Add("汉堡");
                    cboCity.Items.Add("科隆");
                    cboCity.Items.Add("法兰克福");
                    cboCity.SelectedIndex = 0;
                    break;
                default:
                    cboCity.Items.Clear();
                    break;
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string str = cboCountry.SelectedItem.ToString() + "：" + cboCity.SelectedItem.ToString();
            MessageBox.Show(str, "国家列表城市", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
